package Threading;

public class demo5 {
    private static boolean isQuit = false;
    public static void main(String[] args) {
        Thread t = new Thread(()->{
           while(!isQuit){
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.getStackTrace();
               }
           }
        });
        t.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.getStackTrace();
        }
        //将isQuit改为true则t线程里的while循环就进不去从而结束线程
        isQuit = true;
        System.out.println("终止t线程");
    }
}
